
import { _decorator, Label, log, UITransform } from 'cc';
import { App } from '../../../Script/App';
import { LayerCfg, LayerBase } from '../../../Script/LayerBase';
const { ccclass, property } = _decorator;

export const PopupCfg: LayerCfg = {
    bundleName: 'Public',
    prefabName: 'Popup'
}

interface PopupData {
    title: string
    msg: string
    btn0Text?: string
    btn1Text?: string
}

export enum PopupResult {
    Yes,
    No
}

@ccclass('Popup')
export class Popup extends LayerBase {
    _ret!: PopupResult;

    @property(Label)
    labelTitle!: Label

    @property(Label)
    labelMsg!: Label

    @property(Label)
    labelBtn0!: Label

    @property(Label)
    labelBtn1!: Label

    init(data: PopupData): void {
        this.labelTitle.string = data.title
        this.labelMsg.string = data.msg
        this.labelBtn0.string = data.btn0Text ?? 'Yes'
        this.labelBtn1.string = data.btn1Text ?? 'No'
    }

    onBtn0() {
        this._ret = 0
        this.close()
    }

    onBtn1() {
        this._ret = 1
        this.close()
    }

    static async show(data: PopupData) {
        return <PopupResult>await App.showLayer(PopupCfg, data)
    }
}
